package com.digitalchina.lxnsy.activity.old;


import android.os.Handler;
import android.os.Message;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.activity.management.EnterpriseAuthActivity;
import com.digitalchina.lxnsy.activity.management.ManagementDetailsV2Activity;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.toolkit.AppInfo;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.xml.AdminXML;
import com.digitalchina.lxnsy.xml.CommonXML;
import com.digitalchina.lxnsy.xml.UserXML;

import static com.digitalchina.lxnsy.toolkit.Utils.setTitleBarTranslucent;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/7/16 13:05
 * 修改备注：
 * ================================================
 */
public class WelcomeActivity extends BaseActivity {
    private final int MSG_WELCOME_SLEEP = 101;
    private final int THREAD_SLEEP_TIME = 1000;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_welcome);
        hideActionBar();
        //设置状态栏透明
        setTitleBarTranslucent(this);
    }

    @Override
    public void initMember() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Message msg = new Message();
                try {
                    Thread.sleep(THREAD_SLEEP_TIME);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                msg.what = MSG_WELCOME_SLEEP;
                mHandler.sendMessage(msg);
            }

        }).start();
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {

            public void handleMessage(Message msg) {

                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG_WELCOME_SLEEP:
                        gotoActivity();
                        break;
                    default:
                        break;
                }
            }

        };
    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    private void gotoActivity() {

        if ("1".equals(AdminXML.getUserType(activity))) {
            // 企业管理员
            if("1".equals(AdminXML.getIsAudit(activity))){
                //审核通过
                GotoUtil.gotoActivity(WelcomeActivity.this, ManagementDetailsV2Activity.class, true);
            }else{
                //其他
                GotoUtil.gotoActivity(WelcomeActivity.this, EnterpriseAuthActivity.class, true);
            }

        }else{
            if (CommonXML.getIsFirstOpenStatus(WelcomeActivity.this).equals(UserXML.USER_IS_LOGIN_VALUE) && AppInfo.getVersionCode(WelcomeActivity.this) == Integer.parseInt(CommonXML.getVersionCode(WelcomeActivity.this)))
                // 首页
                GotoUtil.gotoActivity(WelcomeActivity.this, MainActivity.class, true);
            else
                // 引导页
                GotoUtil.gotoActivity(WelcomeActivity.this, GuideActivity.class, true);
        }

    }
}
